package com.sry.blog.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sry.blog.sys.mapper.ContentMapper;
import com.sry.blog.sys.model.Content;
import com.sry.blog.sys.service.ContentService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * InnoDB free: 10240 kB; (`article_id`) REFER `blog/article`(`id`) ON UPDATE CASCA 服务实现类
 * </p>
 *
 * @author SR_Y
 * @since 2022-01-05
 */
@Service
public class ContentServiceImpl extends ServiceImpl<ContentMapper, Content> implements ContentService {

    @Override
    public boolean creatOrUpdate(Content content) {
        return saveOrUpdate(content);
    }

    @Override
    public Content getOne(Content content) {
        final Integer articleId = content.getArticleId();
        final Integer replyId = content.getReplyId();
        final String contentContent = content.getContent();
        final Date time = content.getTime();
        return null;
    }

    @Override
    public List<Content> list(Content content) {
        //生成查询条件
        final Integer articleId = content.getArticleId();
        final Integer replyId = content.getReplyId();
        final String contentContent = content.getContent();
        final Date time = content.getTime();
        QueryWrapper<Content> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<Content> lambda = wrapper.lambda();
        if(null!=articleId){
            lambda.eq(Content::getArticleId,articleId);
        }
        wrapper.ne("id",0);
        wrapper.eq("isdelete",0);
        return list(wrapper);
    }

    @Override
    public Page<Content> getCommentTable(Content comment,Integer pageNum, Integer pageSize) {
        Page<Content> page = new Page<>(pageNum,pageSize);
        QueryWrapper<Content> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<Content> lambda = wrapper.lambda();
        if (null != comment.getArticleId()) {
            lambda.eq(Content::getArticleId, comment.getArticleId());
        }
        if (null != comment.getArticleId()) {
            lambda.eq(Content::getArticleId, comment.getArticleId());
        }
        if (StrUtil.isNotEmpty(comment.getContent())) {
            lambda.like(Content::getContent, comment.getContent());
        }
        if (null != comment.getTime()) {
            lambda.eq(Content::getTime, comment.getTime());
        }
        wrapper.ne("id",0);
        return page(page, wrapper);
    }


}
